<!DOCTYPE html>
<html>

	<head>
		<meta charset="utf-8">
		<title>
			取货验证
		</title>
		<meta name="renderer" content="webkit">
		<meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
		<meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1">
		<meta name="apple-mobile-web-app-status-bar-style" content="black">
		<meta name="apple-mobile-web-app-capable" content="yes">
		<meta name="format-detection" content="telephone=no">
		<link rel="stylesheet" href="./css/x-admin.css" media="all">
		<link href="css/xtiper.css" type="text/css" rel="stylesheet" />
		<script src="js/xtiper.min.js" type="text/javascript"></script>
	</head>

	<body>
		<div class="x-nav">
			<a class="layui-btn layui-btn-small" style="line-height:1.6em;margin-top:3px;float:right" href="javascript:location.replace(location.href);" title="刷新"><i class="layui-icon" style="line-height:30px">ဂ</i></a>
		</div>
		<div class="x-body">
			<form class="layui-form x-center" style="width:40%">
				<div class="layui-form-pane" style="margin-top: 15px;">
					<div class="layui-form-item">
						<label class="layui-form-label">手机号码</label>
						<div class="layui-input-inline">
							<input type="text" id="number" placeholder="手机号码" class="layui-input">
						</div>
					</div>
					<div class="layui-form-item">
						<label class="layui-form-label">验证码</label>
						<div class="layui-input-inline">
							<input type="text" id="yanzm" placeholder="验证码" class="layui-input">
						</div>
						<div class="layui-input-inline" style="width:50px;">
							<button class="layui-btn" onclick="check()">验证</button>
						</div>
					</div>
				</div>
			</form>
		</div>
		<div id="list">

		</div>
		<script src="./lib/layui/layui.js" charset="utf-8"></script>

		<script src="js/jquery.min.js"></script>
		<!--去除mobile js和css导致的loading-->
		<script type="text/javascript">
			$(document).bind('mobileinit', function() {
				$.mobile.loadingMessage = false;
			})
		</script>
		<script src="js/jquery.mobile.min.js"></script>
		<script type="text/javascript">
			function check() {
				var customerNumber = $("#number").val();
				var orderIdentify = $("#yanzm").val();
				var url = 'http://127.0.0.1:8080/order/check?customerNumber=' + customerNumber + '&orderIdentify=' + orderIdentify;
				var settings = {
					"url": url,
					"method": "GET",
					"timeout": 0,
					"headers": {
						"Content-Type": "application/json"
					},
				};

				$.ajax(settings).done(function(response) {
					if(response == "") {
						xtip.msg("无订单，请验证是否输入有误");
						setTimeout(function (){
							location.href = "check.html";
						},1000)
					} else {
						$('#list').empty();
						var html = "";
						var sum = 0;
						var msg = "";
						html += '<form class=\"layui-form x-center\"  style=\"width:40%;\">';
						html += '<h2>查询到该订单';
						html += '<div class=\"layui-input-inline\" style=\"width:50px;margin-left: 50px;\">';
						html += '<button class=\"layui-btn\" onclick=\"sureorder()\">确认</button>';
						html += '</div></h2></form> ';
						html += '<div class=\"x-body\"> <div class=\"pd-20\"> <table class=\"layui-table\">';
						html += ' <thead> <tr> <th> 商品名 </th> <th> 商品图片 </th> <th> 商品价钱 </th> <th> 商品数量 </th> </tr> </thead> <tbody >';
						for(var i = 0; i < response.length; i++) {
							msg += '<tr><td>' + response[i].speciesName + '</td>';
							msg += '<td><img  src=\"images/speciesImg/' + response[i].speciesImg + '\" width=\"100\" ></td>';
							msg += '<td>￥' + response[i].price + '&nbsp;&nbsp;&nbsp;单位' + response[i].unitName + '/g</td>';
							msg += '<td>' + response[i].orderdetailNumber + '</td> </tr>';
							sum = sum + response[i].price * response[i].orderdetailNumber;
						}
						html += msg;
						html += ' </tbody>';
						html += ' <div class=\"pd-20\"> <table class=\"layui-table\"> <thead> <tr> <th>下单时间：</th>';
						html += '	<th><a>' + response[0].ordertime + '</a></th></tr>';
						html += '</thread></table></div> </table>';
						html += '<div class=\"pd-20\"><table class=\"layui-table\"><tr><th>总金额</th>';
						html += '<th>￥<a >' + sum + '</a></th></tr></table> </div> </div> </div>';
						$("#list").html(html);
					}
				});
			}
			
			function sureorder() {
				var customerNumber = $("#number").val();
				var orderIdentify = $("#yanzm").val();
				var url = 'http://127.0.0.1:8080/order/sure?customerNumber=' + customerNumber + '&orderIdentify=' + orderIdentify;
				var settings = {
					"url": url,
					"method": "GET",
					"timeout": 0,
					"headers": {
						"Content-Type": "application/json"
					},
				};

				$.ajax(settings).done(function(response) {
					if(response!=0){
						up(response);
					}else{
						xtip.msg('失败');
					}
				});
			}
			function up(orderId) {
				var url = 'http://127.0.0.1:8080/order/update';
				$.ajax({
					type: "post", //post方式传输，比get更加密安全
					url: url, //请求地址
					data: JSON.stringify({
						"orderId": orderId,
						"state": {
							"stateName": "已完成"
						}
					}), //打包data
					dataType: "json",
					contentType: "application/json;charsetset=UTF-8",
					success: function(data) {
					xtip.msg('验证成功');
					},
					error: function() {
						xtip.msg("失败");
					}
				})
			}
		</script>
	</body>

</html>